import { Component, OnInit } from '@angular/core';
import { BehaviorSubject, of, Observable } from 'rxjs';
import { catchError, map, debounceTime, switchMap } from 'rxjs/operators';
import { SysroleService } from 'sparrow-permission-lib';
import { Pageable, PageableResponse, Sysrole } from 'src/app/domain/sparrow';

@Component({
  selector: 'app-sysrole-search',
  templateUrl: './sysrole-search.component.html',
  styleUrls: ['./sysrole-search.component.css']
})
export class SysroleSearchComponent implements OnInit {

  constructor(private sysroleService: SysroleService) { }

  pageable: Pageable = {page: 0, size: 10}
  ngOnInit(): void {

  }

  // for permission
  optionList: any[] = [];
  selectedUser?: any[];
  isLoading = false;

  onSearch(value: string): void {
    this.isLoading = true;
    this.sysroleService
      .all({ page: 0, size: 100 }, value === '' ? undefined : { name: value })
      .subscribe((res) => {
        this.optionList = res.content!;
        this.isLoading = false;
      });
  }

}
